<?php
/**
 * OpenID example Controller
 * @author Ziumin
 * @package OpenID
 */
namespace Bundle\OpenIDBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\SessionStorage;

/**
 * OpenID example Controller
 * @uses OpenIDService
 */
class OpenIDController extends Controller
{
	/**
	 * Example Action that sends OpenID request
	 * and recieves returned attributes
	 * @uses OpenIDService::start()
	 * @uses OpenIDService::finsh()
	 */
	public function showAction()
	{
		/*
		 * Get OpenIDService
		 */
		$oid = $this->get('openid');
		
		/*
		 * If it is first user request
		 */
		if (count($_GET) == 0)
		{
			/*
			 * Redirect user to provider's authentification page
			 */
			$resp = $oid->start();
			if ($resp) return $resp;
			
			/*
			 * Or just die on error
			 */
			die('Invalid ID or another error happened');
		} else {
			
			/*
			 * When OpenID provider returned parameters via _GET
			 *  check them and show
			 */
			$attributes = $oid->finish();
			if ($attributes) 
			{
				var_dump($attributes);
				die();	
			}
			
			/*
			 * Or just die on error
			 */
			die('User canceled request or another error happened (validation failed, etc...)');
		}
	}
}